#ifndef		__ENTITY_MANAGER_BASE_
#define		__ENTITY_MANAGER_BASE_


#include "EntityManagerIf.h"

//
//	Entity Manager
//	
//
class TCOM_API  EntityManager : public IEntityManager
{
public:
	EntityManager(bool bLoad = true);
	virtual	~EntityManager()	{}

	virtual IEntity*	getEntity(int nID);

	//
	//	add/remove entities
	//
	//	add/remove entities
	//
	virtual bool	addEntity(int nID, IEntity*  e);
	virtual bool	addEntity(int nID, IEntityBuilder* b);
	virtual bool	rmvEntity(int nID, IEntity*& e);

	//
	//	visit all entities in current manager
	//
	virtual void	forEach(IEntityVisitor& v);
public:
	//
	//	for gene host
	//
	//	add/remove gene to gene host
	//	Note that gene is organized by group id in gene
	//
	virtual bool addGene(IGeneCreateData* pDynamicData);
	virtual	bool addGene(IGene*);
	virtual bool rmvGene(int nGrpID);

	//
	//	register/unregister an gene event to gene host
	//	gene host will broadcast gene event only to those who has already registered it
	//
	virtual bool	addRegEvt(int nEvtGrp, int nEvt, IGene* pGene);
	virtual bool	rmvRegEvt(int nEvtGrp, int nEvt, IGene* pGene);

	//
	//	fire an gene event to all registered gene on current host
	//	
	virtual bool onEvent(IEvt& evt);
private:
	bool	m_bLoad;// load entity when adding

	typedef stdext::hash_map<int, IEntity*>	EntityMap;
	EntityMap				m_theEntities;
};

#endif
